library("tidyverse")
library("firatheme")
library("prediction")
library("estimatr")
library("texreg")
library("visreg")

# load data
load("~/df_replication_bounded.RData")

# Table SI 9
missing <- subset(df_replication_bounded, Status.y == "Email Bounced" | Status.y == "Email Failed") 
table(missing$treatment)
table(missing$issue)
table(missing$cue)

# Table SI 10

#no click
model5 <- lm_robust(click ~ cue + issue + region + party_name, data = df_replication_bounded, se_type="HC2")
summary(model5)
confint(model5, level = 0.95)

#all clicked
df_replication_bounded$click[df_replication_bounded$Status.y == "Email Bounced"] <- 1
df_replication_bounded$click[df_replication_bounded$Status.y == "Email Failed"] <- 1
model5 <- lm_robust(click ~ cue + issue + region + party_name, data = df_replication_bounded, se_type="HC2")
summary(model5)
confint(model5, level = 0.95)

#media clicked 30% other zero 
media1 <- subset(df_replication_bounded, Status.y == "Email Bounced"  & cue == "the_media") 
media2 <- subset(df_replication_bounded, Status.y == "Email Failed"  & cue == "the_media") 
media <- rbind(media1, media2)

media$click <- rbinom(length(media$click), 1 , 0.30)
table(media$click)

df_replication_bounded <- subset(df_replication_bounded, !(cue %in% "the_media" & Status.y %in% c('Email Bounced', 'Email Failed'))) 
df_replication_bounded <- rbind(df_replication_bounded, media)
model5 <- lm_robust(click ~ cue + issue + region + party_name, data = df_replication_bounded, se_type="HC2")
summary(model5)
confint(model5, level = 0.95)

#climate clicked 30% other zero 
climate1 <- subset(df_replication_bounded, Status.y == "Email Bounced"  & issue == "climate") 
climate2 <- subset(df_replication_bounded, Status.y == "Email Failed"  & issue == "climate") 
climate <- rbind(climate1, climate2)

climate$click <- rbinom(length(climate$click), 1 , 0.30)
table(climate$click)

df_replication_bounded <- subset(df_replication_bounded, !(issue %in% "climate" & Status.y %in% c('Email Bounced', 'Email Failed'))) 
df_replication_bounded <- rbind(df_replication_bounded, climate)
model5 <- lm_robust(click ~ cue + issue + region + party_name, data = df_replication_bounded, se_type="HC2")
summary(model5)
confint(model5, level = 0.95)
